home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_051 / bison / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  121 lines

  1. /* Top level entry point of bison,
  2.    copyright (C) 1984 Bob Corbett and Richard Stallman
  3.  
  4.    Permission is granted to anyone to make or distribute verbatim copies of this program
  5.    provided that the copyright notice and this permission notice are preserved;
  6.    and provided that the recipient is not asked to waive or limit his right to
  7.    redistribute copies as permitted by this permission notice;
  8.    and provided that anyone possessing an executable copy
  9.    is granted access to copy the source code, in machine-readable form,
  10.    in some reasonable manner.
  11.  
  12.    Permission is granted to distribute derived works or enhanced versions of
  13.    this program under the above conditions with the additional condition
  14.    that the entire derivative or enhanced work
  15.    must be covered by a permission notice identical to this one.
  16.  
  17.    Anything distributed as part of a package containing portions derived
  18.    from this program, which cannot in current practice perform its function usefully
  19.    in the absense of what was derived directly from this program,
  20.    is to be considered as forming, together with the latter,
  21.    a single work derived from this program,
  22.    which must be entirely covered by a permission notice identical to this one
  23.    in order for distribution of the package to be permitted.
  24.  
  25.  In other words, you are welcome to use, share and improve this program.
  26.  You are forbidden to forbid anyone else to use, share and improve
  27.  what you give them.   Help stamp out software-hoarding!  */
  28.  
  29. #include <stdio.h>
  30.  
  31. extern    int lineno;
  32. extern    int verboseflag;
  33.  
  34.  
  35. main(argc, argv)
  36. int argc;
  37. char *argv[];
  38. {
  39.   lineno = 0;
  40.   getargs(argc, argv);
  41.   openfiles();
  42.  
  43.   /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
  44.      In file reader.
  45.      The other parts are recorded in the grammar; see gram.h.  */
  46.   reader();
  47.  
  48.   /* record other info about the grammar.  In files derives and nullable.  */
  49.   set_derives();
  50.   set_nullable();
  51.  
  52.   /* convert to nondeterministic finite state machine.  In file LR0.
  53.      See state.h for more info.  */
  54.   generate_states();
  55.  
  56.   /* make it deterministic.  In file lalr.  */
  57.   lalr();
  58.  
  59.   /* Find and record any conflicts: places where one token of lookahead is not
  60.      enough to disambiguate the parsing.  Resolve conflicts. In file
  61.      conflicts. */
  62.   initialize_conflicts();
  63.  
  64.   /* print information about results, if requested.  In file print. */
  65.   if (verboseflag)
  66.     verbose();
  67.   else
  68.     terse();
  69.  
  70.   /* output the tables and the parser to ftable.  In file output. */
  71.   output();
  72.   done(0);
  73. }
  74.  
  75.  
  76.  
  77. /* functions to report errors which prevent a parser from being generated */
  78.  
  79.  
  80. fatal(s)
  81. char *s;
  82. {
  83.   fprintf(stderr, "\nerror at line %d:  %s\n", lineno, s);
  84.   done(1);
  85. }
  86.  
  87.  
  88. fatals(fmt, s)
  89. char *fmt;
  90. char *s;
  91. {
  92.   char buffer[200];
  93.  
  94.   sprintf(buffer, fmt, s);
  95.   fatal(buffer);
  96. }
  97.  
  98.  
  99.  
  100. toomany(s)
  101. char *s;
  102. {
  103.   char buffer[200];
  104.  
  105.   sprintf(buffer, "limit exceeded, too many %s", s);
  106.   fatal(buffer);
  107. }
  108.  
  109.  
  110.  
  111. berror(s)
  112. char *s;
  113. {
  114.   fprintf(stderr, "internal error, %s\n", s);
  115. #ifdef unix
  116.   abort();
  117. #else
  118.   exit(1);
  119. #endif
  120. }
  121.